<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <title></title>
    <link rel="stylesheet" href="./css/base.css"/>
    <link rel="stylesheet" href="./css/doctor-zhifu.css"/>
</head>
<body>
<div class="warp">
    <header class="clearfix">
        <a  class="back fl"></a>
        提交订单
    </header>
    <div class="main">
       <div class="server_box">
           <ul>
               <li><strong class="server_p">服务人员</strong><span id="name">上医·王朝阳</span></li>
               <li><strong class="technical ">职&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称</strong><span id="zhuzhi">主治医生</span></li>
               <li><strong class="price">服务价格</strong><span id="price">￥238元</span></li>
           </ul>
       </div>
        <div class="relation">
            <ul>
                <li><label for="user" class="user">联系姓名<input type="text" placeholder="请输入您的姓名" id="user"/></label></li>
                <li><label for="photo" class="photo">联系电话<input type="number" placeholder="请输入您的联系电话" id="photo" onblur="checkphone();"/></label></li>
                <li><label for="address" class="address">服务地址<input type="text" placeholder="请输入您的服务地址" id="address"/></label></li>
                <li><label for="remark" class="remark">备注信息<input type="text" placeholder="用户的需要或疑问，包括其他情况备注
便于服务前的准备" id="remark"/></label></li>
            </ul>
        </div>
        <div class="pay">
            <ul>
                <li><strong class="server_p">支付金额</strong><span id="num">￥238元</span></li>

            </ul>
        </div>
    </div>
    <footer>
        <div class="answers">
            <button id="btn">预约支付</button>
        </div>

    </footer>
</div>
</body>
<script src="./js/base.js"></script>
<script src="./js/jquery-1.12.4.js"></script>
<script src="./lib/layer/layer.js"></script>
<script src="./js/zhifu.js"></script>
<script>

    function checkphone() {
        var phone = $("#photo").val();
        var reg = '^(1)[0-9]{10}$';
        var flag = phone.match(reg);
        if (!flag) {
            layer.open({
                content: "手机号码格式错误，请重新确认",
                btn: ['确定',]
            });
            return;
        }
    }

    $('.back').click(function () {
        window.history.back();
    })
    var Request = new Object();
   // var url=decodeURI(window.location.search);
    var url=window.location.search;
        function getInfo() {
            if (url.indexOf("?") != -1) {
                var str = url.substr(1)　//去掉?号
                var strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    Request[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
                }
            }
            console.log(Request["server"]);
            console.log(Request["zc"]);
            console.log(Request["price"]);
            console.log(Request["tianshu"]);
            $('#name').text(Request["server"]);
            $('#zhuzhi').text(Request["zc"]);
            $('#price').text("￥"+Request["price"]+"元/"+Request["tianshu"]+"天");
            $('#num').text("￥"+Request["price"]+"元");
        }
  getInfo();
        //
        $('#btn').click(function () {
            var sessionid=sessionStorage['sessionId'];
            var name=$('#user').val();
            console.log(!name);
            if(!name){
                layer.open({
                    content: "请填写姓名！"
                    , btn: ['确定',],
                    skin: 'my-skin'
                    , yes: function (index) {
                        layer.close(index);
                    }
                });
                return;
            }
            var phone=$('#photo').val();
            if(!phone){
                layer.open({
                    content: "请填写联系电话！"
                    , btn: ['确定',],
                    skin: 'my-skin'
                    , yes: function (index) {
                        layer.close(index);
                    }
                });
                return;
            }
            var address=$('#address').val();
            if(!address){
                layer.open({
                    content: "请填写地址！"
                    , btn: ['确定',],
                    skin: 'my-skin'
                    , yes: function (index) {
                        layer.close(index);
                    }
                });
                return;
            }
            var price=Request["price"];
            var quntity=Request["tianshu"];
            var serviceId=sessionStorage['serviceId'];
            var memo=$('#remark').val();//备注
            var data={sessionid:sessionid,name:name,phone:phone,address:address,amount:price,quntity:quntity,serviceId:serviceId,memo:memo,type:0};
            console.log(data);
            $.post(baseURL+"/yuesao/order/saveOrder",data,function (result) {
                if(result.code=="USR000"){
                    var orderNumber=result.data;
                    payMethod(orderNumber,"one.html","zhifu-dingdan.html");
                   // window.location.href=baseURL+"pay/create?orderId="+r.data+"&returnUrl=http://ys.stevengg.com/yuesao_h5/one.html";
                }else if(result.code=="USR138"){
//                    layer.open({
//                        content: result.msg
//                        , btn: ['确定',],
//                        skin: 'my-skin'
//                        , yes: function (index) {
//                            layer.close(index);
//                        }
//                    });
                }else if(result.code=="USR100"){
//                    layer.open({
//                        content: result.msg
//                        , btn: ['确定',],
//                        skin: 'my-skin'
//                        , yes: function (index) {
//                            layer.close(index);
//                        }
//                    });
                }else if(result.code=="USR201"){
//                    layer.open({
//                        content: result.msg
//                        , btn: ['确定',],
//                        skin: 'my-skin'
//                        , yes: function (index) {
//                            layer.close(index);
//                        }
//                    });
                }else if(result.code=="USR124"){
                    layer.open({
                        content: result.msg
                        , btn: ['确定',],
                        skin: 'my-skin'
                        , yes: function (index) {
                            layer.close(index);
                            window.location.href="login.html"
                        }
                    });
                }else if(result.code=="USR103"){
                    layer.open({
                        content:"您有未支付订单，请先支付"
                        , btn: ['确定',],
                        skin: 'my-skin'
                        , yes: function (index) {
                            layer.close(index);
                            window.location.href="zhifu-dingdan.html";
                        }
                    });
                }
            })
        })
</script>
</html>